﻿<%
Class sangong_class
    Public Function online()
        dim rs,sql,str
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select count(*) as nid FROM qingtian_reton where DATEDIFF('h', [time], now()) < 1"
	Rs.Open Sql,cn,1,1
	if not (rs.bof and rs.eof) then
		str=rs("nid")
	else
		str=0
	end if
	Rs.close
	set rs=nothing
	online=str
     End Function
    Public Function tj()
        dim rs,sql,i
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select * FROM qingtian_reton where nid="&qingtian.nid
	Rs.Open Sql,cn,1,3
	if not (rs.bof and rs.eof) then
        rs("time")=now
	else
	rs.addnew
        rs("time")=now
	rs("nid")=qingtian.nid
	end if
	rs.update
	Rs.close
	set rs=nothing
     End Function
    Public Function pd(str)
        dim rs,sql,strr
        strr=str
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select money FROM qingtian_fangjian where id="&strr
	Rs.Open Sql,cn,1,1
	if not (rs.bof and rs.eof) then
           if conn.execute("select money from [qingtian_user] where sid='"&qingtian.Formatsid(sid)&"'")("money")<rs("money") then
           qingtian.err("你的"&qingtian.bi&"不足,进入该房间最小需要"&rs("money")&""&qingtian.bi&".<a href='index.asp?sid=" & sidd & "'>返回重选房间</a>")
           end if
        else
           qingtian.err("没有该房间,<a href='index.asp?sid=" & sidd & "'>返回重选房间</a>")
	end if
	Rs.close
	set rs=nothing
     End Function
    Public Function moname(str)
        dim rs,sql,i,strr,moname1
        strr=str
        moname1=""
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select nid FROM qingtian_reton where aid="&strr
	Rs.Open Sql,cn,1,1
	if not (rs.bof and rs.eof) then
	For i=1 to rs.RecordCount
        if i=1 then
        moname1="<a href='/user/spacev.asp?urls=/game/sangon/index.asp&amp;nid="&rs("nid")&"&amp;sid="&sidd&"'>"&qingtian.name(rs("nid"))&"</a>"
        else
        moname1="<a href='/user/spacev.asp?urls=/game/sangon/index.asp&amp;nid="&rs("nid")&"&amp;sid="&sidd&"'>"&qingtian.name(rs("nid"))&"</a>" & "," & moname1
        end if
	Rs.MoveNext
	next
        else
        moname1="暂无玩家"        
	end if
	Rs.close
	set rs=nothing
        moname=moname1
     End Function
    Public Function moname3(str,str2)
        dim rs,sql,i,strr,strr2
        strr=str
        strr2=str2
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select top 1 nid FROM qingtian_reton where aid="&strr&" and ton=2"
	Rs.Open Sql,cn,1,1
	if not (rs.bof and rs.eof) then
        moname3="(<a href='/user/spacev.asp?urls=/game/sangon/index.asp&amp;nid="&rs("nid")&"&amp;sid="&sidd&"'>"&qingtian.name(rs("nid"))&"</a>)"
        else
        moname3="(空)[<a href='gamed.asp?act=1&amp;pid="&strr2&"&amp;id="&strr&"&amp;sid="&sidd&"'>坐庄</a>]"     
	end if
	Rs.close
	set rs=nothing
     End Function
    Public Function moname2(str,str2)
        dim rs,sql,i,strr,strr2
        strr=str
        strr2=str2
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select nid FROM qingtian_reton where aid="&strr&" and ton<>2"
	Rs.Open Sql,cn,1,1
	if not (rs.bof and rs.eof) then
	For i=1 to rs.RecordCount
        if i=1 then
        moname2="<a href='/user/spacev.asp?urls=/game/sangon/index.asp&amp;nid="&rs("nid")&"&amp;sid="&sidd&"'>"&qingtian.name(rs("nid"))&"</a>"
        else
        moname2="<a href='/user/spacev.asp?urls=/game/sangon/index.asp&amp;nid="&rs("nid")&"&amp;sid="&sidd&"'>"&qingtian.name(rs("nid"))&"</a>" & "," & moname1
        end if
	Rs.MoveNext
	next
        else
        moname2="空"     
	end if
	Rs.close
	set rs=nothing
        moname2="("&moname2&")[<a href='gamed.asp?act=2&amp;pid="&strr2&"&amp;id="&strr&"&amp;sid="&sidd&"'>坐闲</a>]"
     End Function
    Public Function tonn()
        dim rs,sql
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select ton,aid,bid FROM qingtian_reton where nid="&qingtian.nid
	Rs.Open Sql,cn,1,1
	if not (rs.bof and rs.eof) then
        if rs("ton")<>0 then
        tonn="状态:游戏中<a href='gamed.asp?action=login&amp;pid="&rs("bid")&"&amp;id="&rs("aid")&"&amp;sid=" & sidd & "'>返回</a>"
        else
        tonn="状态:等待游戏"
	end if
	end if
	Rs.close
	set rs=nothing
     End Function
    Public Function mobe(str)
        dim rs,sql,i,strr,moname1
        strr=str
        moname1=""
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select nid FROM qingtian_reton where aid="&strr
	Rs.Open Sql,cn,1,1
	if not (rs.bof and rs.eof) then
        moname1=rs.RecordCount
        else
        moname1=0
	end if
	Rs.close
	set rs=nothing
        mobe=moname1
     End Function
    Public Function moton(str,str1,str2)
        dim rs,sql,i,strr,strr1,strr2
        strr=str
        strr1=str1
        strr2=str2
        select case strr
        case "0"
        moton="等待玩家<a href='gamed.asp?pid="&strr2&"&amp;id="&strr1&"&amp;sid=" & sidd & "'>加入</a>"
        case "1"
        moton="游戏正在进行中"
        End Select
        if mobe(strr1)=4 then moton="游戏正在进行中"
     End Function
    Public Function suiji(str)
        dim monber,j,i,strr,temp,a,a1,a2
        strr=str
        monber="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52"
        monber=split(monber,",")
        Randomize()
        a=int(rnd*12+1)
        for i=1 to 50 
            a1=int(rnd*51+1)
            a2=int(rnd*51+1)
        temp=monber(a1)
        monber(a1)=monber(a2)
        monber(a2)=temp
        next
        for i=1 to str
        if i=1 then 
        suiji=monber(a)
        else
        suiji=suiji&","&monber(a+i)
        end if
        next       
     End Function
    Public Function namefa(str,str1)
        dim rs,sql,strr,moname1,strr1
        strr=str
        strr1=str1
        moname1=""
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select "&strr&" FROM qingtian_fangd where id="&strr1
	Rs.Open Sql,cn,1,1
	if not (rs.bof and rs.eof) then
        moname1=rs(0)
        else
        qingtian.err("没有该房间,<a href='index.asp?sid=" & sidd & "'>返回重选房间</a>")
	end if
	Rs.close
	set rs=nothing
        namefa=moname1
     End Function
    Public Function namere(str,str1)
        dim rs,sql,strr,moname1,strr1
        strr=str
        strr1=str1
        moname1=""
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select "&strr&" FROM qingtian_reton where nid="&strr1
	Rs.Open Sql,cn,1,1
	if not (rs.bof and rs.eof) then
        moname1=rs(0)
	end if
	Rs.close
	set rs=nothing
        namere=moname1
     End Function
    Public Function namejian(str,str1)
        dim rs,sql,strr,moname1,strr1
        strr=str
        strr1=str1
        moname1=""
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select "&strr&" FROM qingtian_fangjian where id="&strr1
	Rs.Open Sql,cn,1,1
	if not (rs.bof and rs.eof) then
        moname1=rs(0)
	end if
	Rs.close
	set rs=nothing
        namejian=moname1
     End Function
    Public Function gameed(str)
        dim strr,rs,sql,a1,a2,a3,c,a,i
        strr=str
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select * FROM qingtian_reton where bid="&strr&" and aid=100000 order by id asc"
	Rs.Open Sql,cn,1,3
		if not (rs.bof and rs.eof)  then
                c=suiji(3*(rs.RecordCount+1))
                c=split(c,",")
                if c(0)>36 then a1=10
                if c(1)>36 then a2=10
                if c(2)>36 then a3=10
                if a1<>10 then 
                a1=c(0) mod 4
                if a1<>0 then
                a1=int(c(0)/4)+1
                else 
                a1=int(c(0)/4)  
                end if
                end if
                if a2<>10 then 
                a2=c(1) mod 4
                if a2<>0 then
                a2=int(c(1)/4)+1
                else 
                a2=int(c(1)/4)  
                end if
                end if
                if a3<>10 then 
                a3=c(2) mod 4
                if a3<>0 then
                a3=int(c(2)/4)+1
                else 
                a3=int(c(2)/4)  
                end if
                end if
                session("a")=(a1+a2+a3) mod 10
                if c(0)>40 and c(1)>40 and c(2)>40 then session("a")=100
                if c(0)>c(1) and c(0)>c(2) then 
                session("b")=c(0)
                elseif c(1)>c(0) and c(1)>c(2) then
                session("b")=c(1)
                elseif c(2)>c(1) and c(2)>c(0) then 
                session("b")=c(2)
                end if
                session("c")=c(0)&","&c(1)&","&c(2)
		For i=1 to rs.RecordCount
                a1=1
                a2=1
                a3=1
                if c(i*3)>36 then a1=10
                if c(i*3+1)>36 then a2=10
                if c(i*3+2)>36 then a3=10
                if a1<>10 then 
                a1=c(i*3) mod 4
                if a1<>0 then
                a1=int(c(i*3)/4)+1
                else 
                a1=int(c(i*3)/4)  
                end if
                end if
                if a2<>10 then 
                a2=c(i*3+1) mod 4
                if a2<>0 then
                a2=int(c(i*3+1)/4)+1
                else 
                a2=int(c(i*3+1)/4)  
                end if
                end if
                if a3<>10 then 
                a3=c(i*3+2) mod 4
                if a3<>0 then
                a3=int(c(i*3+2)/4)+1
                else 
                a3=int(c(i*3+2)/4)  
                end if
                end if
                a=(a1+a2+a3) mod 10
                if c(i*3)>40 and c(i*3+1)>40 and c(i*3+2)>40 then a=100
                rs("a")=a
                if c(i*3)>c(i*3+1) and c(i*3)>c(i*3+2) then 
                rs("b")=c(i*3)
                elseif c(i*3+1)>c(i*3) and c(i*3+1)>c(i*3+2) then
                rs("b")=c(i*3+1)
                elseif c(i*3+2)>c(i*3) and c(i*3+2)>c(i*3+1) then 
                rs("b")=c(i*3+2)
                end if
                rs("c")=c(i*3)&","&c(i*3+1)&","&c(i*3+2)
	        rs.update                
		Rs.MoveNext
		next           
		end if
		Rs.close
	set rs=nothing
     End Function
    Public Function game(str)
        dim strr,rs,sql,a1,a2,a3,c,a,i
        strr=str
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select * FROM qingtian_reton where aid="&strr&" order by id asc"
	Rs.Open Sql,cn,1,3
		if not (rs.bof and rs.eof)  then
                c=suiji(3*rs.RecordCount)
                c=split(c,",")
		For i=1 to rs.RecordCount
                a1=1
                a2=1
                a3=1
                if c((i-1)*3)>36 then a1=10
                if c((i-1)*3+1)>36 then a2=10
                if c((i-1)*3+2)>36 then a3=10
                if a1<>10 then 
                a1=c((i-1)*3) mod 4
                if a1<>0 then
                a1=int(c((i-1)*3)/4)+1
                else 
                a1=int(c((i-1)*3)/4)  
                end if
                end if
                if a2<>10 then 
                a2=c((i-1)*3+1) mod 4
                if a2<>0 then
                a2=int(c((i-1)*3+1)/4)+1
                else 
                a2=int(c((i-1)*3+1)/4)  
                end if
                end if
                if a3<>10 then 
                a3=c((i-1)*3+2) mod 4
                if a3<>0 then
                a3=int(c((i-1)*3+2)/4)+1
                else 
                a3=int(c((i-1)*3+2)/4)  
                end if
                end if
                a=(a1+a2+a3) mod 10
                if c((i-1)*3)>40 and c((i-1)*3+1)>40 and c((i-1)*3+2)>40 then a=100
                rs("a")=a
                if c((i-1)*3)>c((i-1)*3+1) and c((i-1)*3)>c((i-1)*3+2) then 
                rs("b")=c((i-1)*3)
                elseif c((i-1)*3+1)>c((i-1)*3) and c((i-1)*3+1)>c((i-1)*3+2) then
                rs("b")=c((i-1)*3+1)
                elseif c((i-1)*3+2)>c((i-1)*3) and c((i-1)*3+2)>c((i-1)*3+1) then 
                rs("b")=c((i-1)*3+2)
                end if
                rs("c")=c((i-1)*3)&","&c((i-1)*3+1)&","&c((i-1)*3+2)
                if i=1 then 
                t=rs("nid")&","&a&","&rs("ton")&":"&c((i-1)*3)&","&c((i-1)*3+1)&","&c((i-1)*3+2)
                else 
                t=t&"|"&rs("nid")&","&a&","&rs("ton")&":"&c((i-1)*3)&","&c((i-1)*3+1)&","&c((i-1)*3+2)
                end if
	        rs.update                
		Rs.MoveNext
		next           
		end if
		Rs.close
	set rs=nothing
                cn.Execute("update qingtian_fangd set c='"&t&"' where id="&strr)
     End Function
    Public Function pai(str)
        dim strr,i,paii,a1
        strr=str
        strr=split(strr,",")
        for i=0 to 2
        a1=paizi(strr(i))
        if tu="&amp;aitd=1'>图片显示</a>" then
        paii=a1&paii
        else
        paii="<img src='img/"&strr(i)&".png' alt='"&a1&"' noselect = 'true' />" & paii
        end if
        next
        pai=paii
     End Function
    Public Function paizi(str)
        dim strr,a1,a2,paizi1
        strr=str
                a2=strr mod 4
                if a2<>0 then
                a1=int(strr/4)+1
                else 
                a1=int(strr/4)  
                end if
                select case a2
                case "0"
                paizi1="黑桃"
                case "1"
                paizi1="方块"
                case "2"
                paizi1="梅花"
                case "3"
                paizi1="红桃"
                End Select
                select case a1
                case "1"
                a1="A"
                case "11"
                a1="J"
                case "12"
                a1="Q"
                case "13"
                a1="K"
                End Select
                paizi=paizi1&a1
     End Function
    Public Function tu()
        dim rs,sql,str
	Set Rs = Server.CreateObject("Adodb.Recordset")
	Sql = "select tu FROM qingtian_reton where nid="&qingtian.nid&""
	Rs.Open Sql,cn,1,3
        if Request.QueryString("aitd")="1" then rs("tu")=0
        if Request.QueryString("aitd")="0" then rs("tu")=1
	rs.update
        if rs("tu") then
        str="&amp;aitd=1'>图片显示</a>"
        else 
        str="&amp;aitd=0'>文字显示</a>"
        end if
	Rs.close
	set rs=nothing
	tu=str
     End Function
end class
set sangong=new sangong_class
%>
